home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / DEV / A-B / 3dlib11.cpt / GrafSys.rel / GrafLib.Fixed / GrafSys.fix.Int next >
Text File  |  1992-04-24  |  10KB  |  206 lines

  1. unit Grafsys;
  2.  
  3. interface
  4. (* uses *)
  5. (* Matrix, Transformations, Data3D, ResourceAccess; *)
  6.  
  7.  
  8.     const
  9.         Res3D = '3Dob'; (* This is the 3D object data resource name *)
  10.  
  11.         MXP = 100; (* maximum number of Points in Object*)
  12.         MXL = 200; (* maximim number of lines in Object *)
  13.         MXPoly = 30; (* maximum number of Polygons per Object *)
  14.         MaxPolyLine = 10; (* Maximum Number of Lines per Polygon *)
  15.  
  16.         Pi = 3.14159265;
  17.  
  18. (* projection Types *)
  19.         parallel = 0;
  20.         perspective = 1;
  21.  
  22. (* Erase Types  *)
  23.         ObjRectFill = 0;
  24.         XorLines = 1;
  25.         WhiteLines = 2; (* draw all Lines in White *)
  26.         BlackLines = 3; (* draw all Lines in Black *)
  27.  
  28.     type
  29.  
  30.         ptsArray = array[1..MaxPolyLine] of integer;
  31.  
  32.         Polygon = record
  33.                 deepz: real; (* maximum (=deepest) z coordinate of this Polygon. For use with HiddenLine/surface *)
  34.                 PointsInPoly: integer; (* number of Lines in this Polygon *)
  35.                 points: ptsArray; (* reference to the Points that make out the Polygon *)
  36.                 Flag: Boolean; (* General Purpose Flag, used in DepthSort *)
  37.             end;
  38.  
  39.         Matrix4 = array[1..4, 1..4] of Fixed;
  40.         Vector4 = array[1..4] of Fixed;
  41.         Point3D = Vector4;
  42.  
  43.         RealVector4 = array[1..4] of Real; (* ATTENTION!!! Compare to the Coprocessor version !!! *)
  44.  
  45.         Line3D = record
  46.                 startpoint, endpoint: Integer; (* Number of 3D-point to draw from and to, both must be within 1 and obj.maxpoint *)
  47.                 newline: boolean; (* Indicates that startpoint is not endpoint from last Line3D *)
  48.             end;
  49.  
  50.         PointArray = array[1..MXP] of Point3D;
  51.         LineArray = array[1..MXL] of Line3D;
  52.         PolyArray = array[1..MXPoly] of Polygon;
  53.  
  54.         Eye3D = record
  55.                 location: Point3D;
  56.                 phi: Real;
  57.                 theta: Real;
  58.                 pitch: Real;
  59.                 ViewAngle: Real;
  60.             end;
  61.  
  62.         Graf3DPtr = ^Grafport3D;
  63.         Grafport3D = record
  64.                 ProjectionPlane: Rect;
  65.                 ViewPlane: Rect;
  66.                 left, right, top, bottom: Integer; (* Window rectangle  *)
  67.                 center: Point; (* center of screen *)
  68.                 MasterTransform: Matrix4; (* Matrix for pretrafo for eye-coords *)
  69.                 eye: Eye3D; (* the Eye of the Camera *)
  70.                 UseEyeFlag: Boolean; (* FALSE --> eye is always at (0,0,0) and looks straight down z *)
  71.                 d: Real; (* Perspective Parameter set up by Viewangle *)
  72.                 Clip: Boolean; (* Tells algorithm if to clip to 3D Pyramid *)
  73.                 HiddenLine: Boolean; (* use Hidden-Line Algorithm on Object *)
  74.                 projectionType: INTEGER; (* parallel or perspective *)
  75.                 versionID: LongInt; (* used to identify changes *)
  76.             end;
  77.  
  78.         screenArray = array[1..MXL] of integer; (* note : mxL, for all screencoords will be stored for all lines *)
  79.         screenPts = array[1..MXP] of integer;
  80.         newLineArray = array[1..MXl] of Boolean;
  81.  
  82. (* ScreenObj : This Data Structure holds an Transformed Object and all its data required to draw it on screen *)
  83. (* OOP : should be an instant of Object3D *)
  84.  
  85.         ScreenObjPtr = ^ScreenObj;
  86.         ScreenObj = record
  87.                 nhmin, nhmax, nvmin, nvmax: integer; (* new rectangles from last calculation *)
  88.                 hmin, hmax, vmin, vmax: integer; (* Rectange in which ScreenObject from SECOND LAST call to ClacScreenObj *)
  89.                 Point: PointArray; (* Transformed Points of object *)
  90.                 deepz: real; (* maximum z of all Transformed Points. Used for Scene-Building *)
  91.                 maxPoint, maxLine, maxPoly: integer; (* number of Points,  Lines and Polygons in this Object *)
  92.                 Line: LineArray;  (* Lines as defined in Parent Object *)
  93.                 screenx: screenPts; (* x-coordinates of all Transformed Points *)
  94.                 screeny: screenPts; (* y-coordinates of all Transformed Points *)
  95.                 screenLines: integer;
  96.                 Autoerase: Boolean;
  97.                 EraseType: Integer;
  98.  
  99.            (* The following data should be used as instances of the same basic object if we convert to *)
  100.            (* OOP Grafsys.                                                                                                                 *)
  101.  
  102.                 screen1x: ScreenArray; (* x-coordinates for clipped lines in CxxxScreenObj *)
  103.                 screen1y: ScreenArray; (*                            - " -                                         *)
  104.                 screen2x: screenArray; (* used in Line-Clipping mode *)
  105.                 screen2y: screenArray; (*         - " -                         *)
  106.                 newLine: newLineArray; (*         - " -                         *)
  107.                 Polygons: PolyArray; (* Polygons as defined in Parent Object *)
  108.  
  109. (* debugging only variables follow *)
  110.  
  111.             end;
  112.  
  113. (* GrafObj : The Representation of Objects for Object Drawing and Transformation *)
  114. (* OOP : would be Object3D *)
  115.  
  116.         GrafObjPtr = ^GrafObject;
  117.         GrafObject = record
  118.                 versionID: LongInt; (* used to identify changes in Eye*)
  119.                 hasChanged: Boolean; (* will be set TRUE after any change to Object *)
  120.                 x, y, z: Real; (* position of object's Origin in 3D-space *)
  121.                 xRot, yRot, zRot: Real; (* rotation of Object to its own origin *)
  122.                 sx, sy, sz: Real; (* objects scaling factors *)
  123.                 Trot: Matrix4; (* internal use : objects trafo-matrix for rotation*)
  124.                 Ttrans: Matrix4; (* internal use only : objects trafo Matrix for translation and scaling *)
  125.                 Tanyrot: Matrix4; (* matrix for additional rotation around any achsis *)
  126.                 Tfreeform: Matrix4; (* internal use only : free translation of object *)
  127.                 maxPoint: Integer; (* number of points in Object, max 100, min 2 *)
  128.                 maxLine: Integer; (* number of Lines in Object, max 200, min 1 *)
  129.                 maxPoly: Integer; (* number of Polygons in Object *)
  130.                 Point: PointArray;
  131.                 Line: LineArray;
  132.                 Polygons: PolyArray;
  133.                 vmax: integer; (* this objects maximal and minimal screen coords after last draw *)
  134.                 vmin: integer;
  135.                 hmin: integer;
  136.                 hmax: integer;
  137.                 AutoErase: Boolean; (* Flag for use with vmax..hmax and the fDrawObject routine *)
  138.                 hasDrawn: Boolean; (* internal use only : for use with erase flag *)
  139.                 EraseType: INTEGER;(* What kind of Erase-Technique for Autoerase *)
  140.                 ScreenObjLink: ScreenObjPtr; (* attached screenobject. defaults to NIL *)
  141.             end;
  142.  
  143. (* procedures to manipulate Grafport *)
  144.     procedure InitGrafSys;   (*  (var Master: Graf3DPtr) -- deleted, since we have GetGrafPort *)
  145.     procedure NewGrafport (thePlane: Rect; var the3DPort: Graf3DPtr);
  146.     procedure SetGrafPort (the3DPort: Graf3Dptr); (* tells grafsys in which port to draw *)
  147.     procedure GetGrafPort (var the3DPort: Graf3dptr); (* get current GrafPort *)
  148.     procedure SetView (ProjectPlaneSize, ViewPlaneSize: Rect);
  149.     procedure SetCenter (x, y: INTEGER);
  150.     procedure SetEye (UseEye: Boolean; x, y, z: REAL; phi, theta, pitch: real; viewangle: real; clipping: boolean);
  151.     procedure geteye (var UseEye: Boolean; var x, y, z, phi, theta, pitch, viewangle: real; var clipping: boolean);
  152.  
  153.  
  154.  
  155. (* routines to generate objects *)
  156.     function NewObject: GrafObjPtr;
  157.     function GetNewObject (theObjectID: INTEGER): GrafObjPtr;
  158.     function GetNewNamedObject (theObjectName: Str255): GrafObjPtr;
  159.     procedure SaveObject (theObject: GrafObjPtr; theName: Str255; ID: integer);
  160.     procedure SaveNamedObject (theObject: GrafObjPtr; theName: Str255; var ID: integer);
  161.     function AddPoint (theObject: GrafObjPtr; x, y, z: Real; var PointCount: integer): boolean;
  162.     function DeletePoint (theObject: GrafObjPtr; PointNumber: integer): Boolean;
  163.     procedure GetPoint (theObject: GrafObjPtr; thePoint: INTEGER; var x, y, z: REAL);
  164.     procedure ChangePoint (theObject: GrafObjPtr; thePoint: integer; x, y, z: real);
  165.  
  166.     function AddLine (theObject: GrafObjPtr; src, tgt: integer): Boolean;
  167.     function DeleteLine (theObject: GrafObjPtr; theLine: INTEGER): Boolean;
  168.     function ChangeLine (theObject: grafObjPtr; theLine: INTEGER; src, tgt: INTEGER): Boolean;
  169.     procedure GetLine (theObject: GrafObjPtr; theLine: INTEGER; var src, tgt: INTEGER; var newline: boolean);
  170.  
  171.     function SetPoly (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10: integer): polygon;
  172.     procedure AddPolygon (theObject: GrafObjPtr; thePolygon: Polygon; var PolyRef: Integer); (* does NOT polygon must have been created *)
  173.     function AddPointToPolygon (theObject: GrafObjPtr; thePolyref, thePointRef: Integer): boolean;
  174.  
  175. (* routines to manipulate object in 3D locally/operationorder-idependent*)
  176.     procedure ResetObject (theObject: GrafObjPtr); (* sets objects rotation and position of origin to 0 *)
  177.     procedure ObjRotate (theObject: GrafObjPtr; dXrot, dYrot, dZrot: real);
  178.     procedure SetObjRot (theObject: GrafObjPtr; Xrot, Yrot, Zrot: real);
  179.     procedure GetObjRot (theObject: GrafObjPtr; var Xrot, Yrot, Zrot: real);
  180.     procedure ObjTranslate (theObject: GrafObjPtr; dx, dy, dz: Real);
  181.     procedure SetObjTranslate (theObject: GrafObjPtr; xTrans, yTrans, zTrans: Real);
  182.     procedure GetObjTranslate (theObject: grafObjPtr; var xTrans, yTrans, zTrans: Real);
  183.     procedure ObjScale (theObject: GrafObjPtr; sx, sy, sz: Real);
  184.     procedure SetObjScale (theObject: GrafObjPtr; xScale, yScale, zScale: Real);
  185.     procedure GetObjScale (theObject: grafObjPtr; var xScale, yScale, zScale: Real);
  186.     procedure ObjRotateArb (theObject: GrafObjPtr; p1, p2: RealVector4; phi: Real); (* rotate local around arbitrary achsis *)
  187.     procedure ResetAnyRot (theObject: GrafObjPtr);
  188.     function ObjPoint (theObject: GrafObjPtr; thePoint: Integer): RealVector4; (* returns the coordinates of object's point if rotation where done *)
  189.     function ObjPointArb (theObject: GrafObjPtr; x, y, z: Real): RealVector4;
  190.  
  191. (* routines to manipulate object in 3D globally/operation-dependent *)
  192.     procedure ObjFreeRotate (theObject: GrafObjPtr; dXrot, dYrot, dZrot: real);
  193.     procedure ObjFreeRotateArb (theObject: GrafObjPtr; p1, p2: RealVector4; phi: Real);
  194.     procedure ObjFreeTranslate (theObject: GrafObjPtr; dx, dy, dz: Real);
  195.     procedure ObjFreeReset (theObject: GrafObjPtr);
  196.  
  197. (* routines to prepare to draw in 3D *)
  198.     procedure SetAutoErase (theObject: GrafObjPtr; Flag: Boolean);
  199.     procedure setprojection (theGrafPort: Graf3DPtr; projectionType: INTEGER);
  200.     procedure ToScreen (x, y, z: real; var h, v: INTEGER);
  201.  
  202.     procedure TransformObject (theObject: GrafObjPtr; var xPointBuf, ypointBuf: screenPts; var hmin, vmin, hmax, vmax: integer; var deepz: Real; var Points: PointArray);
  203.  
  204.  
  205. implementation
  206. end.